﻿using SimpleESBCore.Implement.Datas;
using SimpleESBCore.Implement.Serializer;
using SimpleESBCore.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleESBCore.Implement
{
    public class FileLog : ILog
    {
        private string logPath;
        private ISerialization serialization;
        public FileLog(string logPath)
        {
            this.logPath = logPath;
            this.serialization = new JSONSerializer();
        }
        public void LogInfo(LogInfoData logInfoData)
        {
            string logInfo = serialization.Serializer(logInfoData);
            if (File.Exists(logPath))
            {
                File.Exists(logPath);
            }

            using (FileStream stream = new FileStream(logPath, FileMode.Append, FileAccess.Write))
            {
                byte[] buffer = Encoding.Unicode.GetBytes(logInfo);
                stream.Write(buffer, 0, buffer.Length);
                stream.Flush();
                stream.Close();

            }
        }
    }
}
